package com.zxw.web;

import com.rabbitmq.client.AMQP;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zxw
 * @date 2021-03-06 14:48
 */
@Configuration
public class Procuder{
    @Autowired
    RabbitTemplate rabbitTemplate;

    @Bean
    public void init() {
        AMQP.Channel channel = new AMQP.Channel();
        Queue queue = new Queue("", true);

    }


    @PostConstruct
    public void send() {
        new Thread(()->{
            while (true){
                Map<String, Object> msg = new HashMap<>();
                msg.put("timestamp", System.currentTimeMillis());
                msg.put("value", 1);
                rabbitTemplate.convertAndSend("test", "test", msg);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
